//
//  BC_Board.h
//  CocOth
//
//  Created by BrunoCausse on 06/11/10.
//  Copyright 2010-2013 poulailler cie. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BC_Const.h"

void init_hashconst();

@class BC_Move;

/*! (double linked) list of squares */
typedef struct SquareList {
	int position;                 /*!< square position */
	struct SquareList *previous;  /*!< link to previous square */
	struct SquareList *next;      /*!< link to next square */
} SquareList;


@interface BC_Board : NSObject <NSCopying> {
	
	char square[BOARD_SIZE];						/*!< square content */
	char player;									/*!< player to move */
	int n_discs[2];									/*!< disc numbers */
	int n_empties;									/*!< number of empty squares */
	SquareList empties[62];							/*!< list of empty squares  60 + 2 sentinels*/
	SquareList *position_to_empties[BOARD_SIZE];	/*!< link position to the list */
    
    unsigned long long hashcode;                    /*!< hashcode */
	
}

@property (readonly, assign) char player;
@property (readonly, assign) int n_empties;
@property (readwrite) unsigned long long hashcode;

- (id)init;
- (id)initWithString:(NSString *)boardString;

- (id)copyWithZone:(NSZone *)zone;

- (BOOL)isLegal:(int)pos;
- (int)generateMove:(BC_Move *)move;
- (int)generateAllMoves:(NSMutableArray *)moveArray;
- (int)getMobility;
- (void)sort_fastfirst:(NSMutableArray *)moves;
- (BOOL)isEndgame;
- (BOOL)shouldPass;

- (void)doMove:(BC_Move *)move;
- (void)undoMove:(BC_Move *)move;
- (void)doPass;

- (int)diff_discs;

- (int)discAtRow:(int)row column:(int)column;
- (BOOL)isLegalAtRow:(int)row column:(int)column;
- (BC_Move *)generateMoveAtRow:(int)row column:(int)column;

- (NSString *)descriptionForScript;
- (NSString *)descriptionForZoo;


@end
